package com.lfnyxy.service.org.imp;

import com.lfnyxy.dao.org.AppMaintenanceDao;
import com.lfnyxy.entity.org.AppMaintenanceEntity;
import com.lfnyxy.query.org.AppMaintenanceQuery;
import com.lfnyxy.service.org.AppMaintenanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppMaintenanceServiceImp implements AppMaintenanceService {
    @Autowired
    public AppMaintenanceDao appMaintenanceDao;

    public int CreateItem(AppMaintenanceEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return appMaintenanceDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(AppMaintenanceEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return appMaintenanceDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List<AppMaintenanceEntity> QueryPageList(AppMaintenanceQuery query) {
        int count = appMaintenanceDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return appMaintenanceDao.QueryPageList(query);
        }
        return null;
    }

    public List<AppMaintenanceEntity> QueryAll() {
        return appMaintenanceDao.QueryAll();
    }

    public AppMaintenanceEntity QueryItem(int Id) {
        if (Id > 0) {
            return appMaintenanceDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return appMaintenanceDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(AppMaintenanceEntity entity) {
        if (entity != null) {
            return appMaintenanceDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}